home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Timothy Knox / yerk 3.66 / Module source / logging < prev    next >
Text File  |  1994-06-24  |  2KB  |  56 lines

  1. \  5/23/93    rfl    Module to echo output to a file
  2. \ vector output to a file like +print, -print
  3. \ will append to existing file
  4. \ hold option key down to select fileName and destination....default named
  5. \   'logfile' in the yerk folder.
  6.  
  7. :Module logMod
  8.  
  9. file logfile    \ don't want this closed on abort. or do i?
  10.  
  11. : typefile write: logfile drop ;
  12. : emitfile  buf255 c! buf255 1 typefile ;
  13. : crfile  13 emitfile ;
  14.  
  15. : echofile      ( -- )              \ should work like +print, but to a file?
  16.     'c typefile -> ptypevec            \ type to the file instead of the printer
  17.         0 -> typevec                \ leave the screen alone
  18.         'c emitfile -> pemitvec        \ emit to the file
  19.         'c crfile -> pcrvec ;        \ cr to file, also
  20.  
  21. : tofile ( -- )    \ should send all output to the file
  22.        'c typefile -> typevec
  23.        'c emitfile -> emitvec
  24.        'c crfile -> crvec ;
  25.  
  26. : toscreen ( -- ) \ back to normal
  27.     'c 2drop ->  ptypevec
  28.     0 -> typevec
  29.     0 -> emitvec
  30.     0 -> crvec ;
  31.  
  32. : nolog toScreen 0 -> pemitVec 0 -> pcrVec ;
  33.  
  34. scon DefName "logFile"
  35.  
  36. \ logging word to create a file to test with
  37. \ returns true if open, false if cancelled by user
  38. : openlog ( -- b) option?
  39.     IF   " Save output to File…" DefName stdPut: logfile        \ select a file
  40.     ELSE DefName name: logfile true            \ default to Yerk folder
  41.     THEN dup
  42.     IF open: logfile konstant fnfErr =        \ want to append to existing file
  43.         IF create: logFile drop THEN
  44.         last: logfile                        \ move to end of file
  45.     THEN   ;
  46.  
  47. : closelog nolog 
  48.     txType saveSig set: logfile
  49.     close: logfile drop ;
  50.  
  51. : +file openlog IF echofile THEN ;
  52. : -file closelog ;
  53. : toFile null ;
  54.  
  55. ;Module
  56.